package org.mysfit.ctp4j.infra.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 操作系统信息判断工具类
 * 
 * @author long.gf
 *
 */
public class TradeTimeUtils {
	
	public static long diffTime(String time1,String time2) {
		Calendar cal1 = Calendar.getInstance();
		cal1.set(Integer.parseInt(time1.substring(0, 4)),
				Integer.parseInt(time1.substring(5, 7)),
				Integer.parseInt(time1.substring(8, 10)),
				Integer.parseInt(time1.substring(11, 13)),
				Integer.parseInt(time1.substring(14, 16)),
				Integer.parseInt(time1.substring(17)));
		
		Calendar cal2= Calendar.getInstance();
		cal2.set(Integer.parseInt(time2.substring(0, 4)),
				Integer.parseInt(time2.substring(5, 7)),
				Integer.parseInt(time2.substring(8, 10)),
				Integer.parseInt(time2.substring(11, 13)),
				Integer.parseInt(time2.substring(14, 16)),
				Integer.parseInt(time2.substring(17)));
		
		return (cal1.getTimeInMillis() - cal2.getTimeInMillis())/1000;
	}
	
	public static String getCurrTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(new Date());
	}
	
	public static int getCurrReqId() {
		SimpleDateFormat sdf = new SimpleDateFormat("MMdd HH:mm:ss");
		String time = sdf.format(new Date()).replaceAll(":", "").replaceAll(" ", "");
		return Integer.parseInt(time);
	}
}
